package com.wn.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author yellow Docter
 * @date 2022 -06-27
 * @desc
 *
 * servlet的作用:
 * 01 拿到浏览器请求
 * 02 处理请求
 * 03 给浏览器回写数据
 *
 *
 * loginServlet的入门程序
 * 01  创建一个类 LoginServlet,需要继承HttpServlet
 *
 * 02  重写 doget/dopost方法
 *
 * 03 处理请求
 *
 * 04 把 LoginServlet配置到 web.xml
 *   1. 启动的创建LoginServlet 初始化对象
 *   2. 请求的url可以通过路径映射到,LoginServlet的类中的方法
 *
 */
public class LoginServlet extends HttpServlet {

    // 处理get请求
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //doget调用dopost
        this.doPost(req,resp);
    }

    // 处理post请求
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        // 拿到请求数据
        String username = req.getParameter("username");
        String password = req.getParameter("password");

        System.out.println("username = " + username);
        System.out.println("password = " + password);

    }
}
